#!/usr/bin/perl 
use strict;

use DBI;
use CGI;
use TTraker;

initialize_dbi();

print_header();

my $form_ref = &parse_input;

my %FORM_DATA = %$form_ref; 
my $num = $FORM_DATA{'empNum'};
my $name = $FORM_DATA{'empName'};
my $job_id = $FORM_DATA{'empJob'};
my $loc = $FORM_DATA{'empLoc'};
my $doc = $FORM_DATA{'docNum'};
my $job = $FORM_DATA{'jobNum'};
my $task = $FORM_DATA{'taskNum'};
my $cli = $FORM_DATA{'cliId'};
my $stamp = $FORM_DATA{'stamp'};
my $activity = $FORM_DATA{'activity'};
my $batch = $FORM_DATA{'batNum'};
my $fld_str = $FORM_DATA{'requery'};

my $task_count = get_task_count ($cli, $job_id, $fld_str);
my $task_ref = get_task_list ($cli, $job_id, $fld_str);
my @tasks = @$task_ref;

my $button_text;

if ( $activity == 2 ) {
	$button_text = "Log Tasks - close job";
} elsif ($activity == 3 ) {
	$button_text = "Log Tasks - keep job open";
} elsif ($activity == 8 ) {
	$button_text = "Log Tasks - keep close job";
} else {
	$button_text = "Log Tasks - ????????";
}

my @checked = ();

if ($fld_str eq "inbound") {
	@checked = ("checked=\"checked\"", "", "");
} elsif ($fld_str eq "outbound") {
	@checked = ("", "checked=\"checked\"", "");
} else {
	@checked = ("", "", "checked=\"checked\"");
}	

print <<ENDHEADER;
<html>
<head>
<link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
<script type='text/javascript' src='${js_ref}trak.js'></script>
<title>trak_02_activity_log_tasks.pl</title>
</head>
<body onload='startTime()'>
<h2><center>${banner}</center></h2>
<hr/>
<div id='clock'></div>
<div id='box1'>
Employee Number:<br/>
Employee Name:<br/>
Client:<br/>
Document ID:<br/>
</div>
<div id='box2'>
<span>$num</span><br/>
<span>$name</span><br/>
<span>$cli</span><br/>
<span>$doc</span><br/><br/>
</div>
<form autocomplete='off' name='select_area' action='${cgi_ref}trak_05_log_tasks_requery.pl' method='post'>
<div id="box1_2">
<input type="hidden" name=empName value='$name'/>
<input type="hidden" name=docNum value='$doc'/>
<input type="hidden" name=jobNum value='$job'/>
<input type="hidden" name=taskNum value='$task'/>
<input type="hidden" name=empNum value='$num'/>
<input type="hidden" name=cliId value='$cli'/>
<input type="hidden" name=stamp value='$stamp'/>
<input type="hidden" name="empJob" value='$job_id' />
<input type="hidden" name=activity value='$activity'/>
<input type="hidden" name=batNum value='$batch'/>
<label><input type="radio" name="requery" value="inbound" $checked[0] /> Inbound</label><br/>
<label><input type="radio" name="requery" value="outbound" $checked[1] /> Outbound </label><br/>
<label><input type="radio" name="requery" value="include" $checked[2] /> All &nbsp&nbsp</label><br/>
<input type='submit' value='Select'>
<br/>
</div>        
</form>
<div id='box5'>
<form onkeypress='return event.keyCode != 13;' autocomplete='off'  name='activity' action='${cgi_ref}trak_05_log_tasks.pl' method='post'>
<input type="hidden" name=empName value='$name'/>
<input type="hidden" name=docNum value='$doc'/>
<input type="hidden" name=jobNum value='$job'/>
<input type="hidden" name=taskNum value='$task'/>
<input type="hidden" name=empNum value='$num'/>
<input type="hidden" name=cliId value='$cli'/>
<input type="hidden" name=stamp value='$stamp'/>
<input type="hidden" name=activity value='$activity'/>
<input type="hidden" name=batNum value='$batch'/>
<table>
<tr>
	<th id='th_right'>Activity</th>
	<th></th>
	<th>Units</th>
</tr>
ENDHEADER
my $count = $#tasks;
for (my $i=0; $i<$count;$i++ ) {
my $code=$tasks[$i][0];
my $desc = $tasks[$i][1];
$desc =~ tr/A-Z/a-z/;
my $units = $tasks[$i][2];
$units =~ tr/A-Z/a-z/;
print <<ENDHEADER;
<tr>
	<td id='description1' >${desc} &nbsp&nbsp </td>
	<td><input type='text' size='4' name='task_${code}'/></td>
	<td>&nbsp&nbsp&nbsp $units</td>
</tr>
ENDHEADER
}
print <<ENDHEADER;
</table>
<br/><br/>
<input type='submit' value='$button_text'>
<br/><br/>
<a href="${cgi_ref}trak_00_start_up.pl">Return to Log-In</a>
<br/><br/>
</form>
</body>
</html>
ENDHEADER

db_disconnect();


